<template>
  <!-- 导入表 -->
  <el-dialog
    fullscreen
    title="物资选择"
    :visible.sync="visible"
    append-to-body
  >
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="物资名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入物资名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入物资编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <template>
      <div>
        <el-radio-group v-model="queryParams.id" @change="getList">
          <el-radio-button
            v-for="productConfig in productConfigOptions"
            :key="productConfig.index"
            :label="productConfig.id"
            >{{ productConfig.typeName }}</el-radio-button
          >
        </el-radio-group>
      </div>
    </template>
    <el-row>
      <el-table
        ref="table"
        :data="stockList"
        @selection-change="handleSelectionChange"
        max-height="550px"
        highlight-current-row
        cell-class-name="li_table"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="库位" align="center" prop="depotName" />
        <el-table-column label="货位" align="center" prop="goodsSpaceName" />
        <el-table-column label="编号" align="center" prop="productCode" />
        <el-table-column label="品名" align="center" prop="productName" />
        <el-table-column
          label="规格型号"
          align="center"
          prop="basicProductInfo.model"
        />
        <el-table-column label="库存量" align="center" prop="inventory" />
        <el-table-column
          label="可用库存"
          align="center"
          prop="availableStock"
        />
        <el-table-column label="单位" align="center" prop="unit" />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" :disabled="clickDisabled" @click="submit"
        >确 定</el-button
      >
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listStock } from "@/api/equipment/materials/stockOutApply";
import { listProduct } from "@/api/equipment/materials/stockIn";
// import { listProductInfo} from "@/api/basic/productInfo/productInfo";
export default {
  data() {
    return {
      clickDisabled: true,
      selectRow: null,
      // 遮罩层
      visible: false,
      // 选中数组值
      tables: [],
      // 总条数
      total: 0,
      // 表数据
      stockList: [],
      //选择的物资列表
      selectProductList: [],
      //物资类型
      productConfigOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        depotId: null,
        goodsSpaceId: null,
        productId: null,
        inventory: null,
        availableStock: null,
        unit: null,
        code: null,
        name: null,
        id: null,
      },
    };
  },
  created() {
    this.getProductConfigList();
  },
  methods: {
    // 显示弹框
    show(id) {
      this.queryParams.depotId = id;
      this.getList();
      this.visible = true;
    },
    getProductConfigList() {
      this.loading = true;
      listProduct().then((response) => {
        this.productConfigOptions = response.data;
        this.loading = false;
      });
    },
    //改变一页的数量
    handleSizeChange(val) {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = val;
      this.getList();
    },
    //改变页码
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    // 查询表数据
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (this.queryParams.code != null) {
        this.queryParams.params["code"] = this.queryParams.code;
      }
      if (this.queryParams.name != null) {
        this.queryParams.params["name"] = this.queryParams.name;
      }
      listStock(this.queryParams).then((response) => {
        this.stockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectProductList = selection;
      this.buttonStatus();
    },
    selectionChange(row) {
      this.selectRow = row;
      this.buttonStatus();
    },
    buttonStatus() {
      if (this.selectProductList == null) {
        this.clickDisabled = true;
      } else {
        this.clickDisabled = false;
      }
    },
    /** 提交按钮 */
    submit() {
      this.$emit("childFn", this.selectProductList);
      this.visible = false;
    },
  },
};
</script>
